import json
import subprocess


def get_disk_type(device_path: str) -> str:
    """判断磁盘是 HDD 还是 SSD"""
    try:
        # 方法1：检查 lsblk 的 ROTA 字段（旋转设备标志）
        lsblk_cmd = ["lsblk", "-d", "-o", "ROTA", "-n", device_path]
        result = subprocess.run(lsblk_cmd, capture_output=True, text=True, check=True)
        data = result.stdout.strip()
        if data=='0':
            return 'SSD'
        else:
            return 'HDD'
    except Exception:
        pass
    return "Unknown"  # 默认返回 Unknown
